home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DClap / DTask.cpp < prev    next >
Text File  |  1996-07-05  |  2KB  |  136 lines

  1. // DTask.cp
  2. // d.g.gilbert
  3.  
  4. #include "Dvibrant.h"
  5. #include "DTask.h"
  6. #include "DTaskMaster.h"
  7.  
  8. #include "DCommand.h"
  9. #include "DView.h"
  10. #include "DViewCentral.h"
  11. #include "DApplication.h"
  12.  
  13.  
  14.  
  15. //class DTask : public DObject
  16.         
  17. void DTask::Process() 
  18.     if (fSource) fSource->ProcessTask(this); 
  19. }
  20.     
  21.  
  22.  
  23.  
  24. // class DCommand : public DTask
  25.  
  26. Global DCommand* gLastCommand;
  27.  
  28.  
  29. DCommand::DCommand() :
  30.         DTask( 0, kCommander, NULL, 0),
  31.         fTitle( NULL),
  32.         fCanUndo( false), 
  33.         fCausesChange( false), 
  34.         fCommandDone(0)
  35.         {}
  36.  
  37. DCommand::DCommand( long command, DTaskMaster* itsSource, char* title ,
  38.                         Nlm_Boolean canUndo, Nlm_Boolean causesChange) :
  39.         DTask( command, kCommander, itsSource, 0),
  40.         fTitle( title),
  41.         fCanUndo( canUndo), 
  42.         fCausesChange( causesChange), 
  43.         fCommandDone(0)
  44.         {}
  45.  
  46.  
  47. void DCommand::ICommand( long command, DTaskMaster* itsSource, char* title,
  48.                         Nlm_Boolean canUndo, Nlm_Boolean causesChange) 
  49. {
  50.     fNumber= command; 
  51.     fSource= itsSource;
  52.     fTitle = title;
  53.     fCanUndo = canUndo;
  54.     fCausesChange = causesChange;
  55. }
  56.         
  57. DCommand::~DCommand() 
  58.     Commit(); 
  59.     if (this == gLastCommand) gLastCommand= NULL;
  60. }
  61.  
  62. void DCommand::Commit() 
  63. {
  64.     if (this == gLastCommand) {
  65.         gViewCentral->DisableView(DApplication::kUndo); 
  66.         fCommandDone= true; //??
  67.         fCanUndo= false;
  68.         // can we delete/NULL gLastCommand ??  
  69.         }
  70. }
  71.  
  72. void DCommand::SetupMenu(char* undo) 
  73.     DView*     undomenu;
  74.     if (fCanUndo) {
  75.         //gViewCentral->EnableView(DApplication::kUndo);   
  76.         undomenu= gViewCentral->GetView(DApplication::kUndo);
  77.         if (undomenu) {
  78.             if (fTitle) {
  79.                 char title[80];
  80.                 sprintf( title, "%s %s", undo, fTitle);
  81.                 undomenu->SetTitle( title);
  82.                 }
  83.             else 
  84.                 undomenu->SetTitle( undo);
  85.             undomenu->Enable();
  86.             }
  87.         }
  88.     else {
  89.         //gViewCentral->DisableView(DApplication::kUndo);   
  90.         undomenu= gViewCentral->GetView(DApplication::kUndo);
  91.         if (undomenu) {
  92.             undomenu->SetTitle("Undo");
  93.             undomenu->Disable();
  94.             }
  95.         }
  96.  
  97. }
  98.  
  99. void DCommand::UndoRedo() 
  100.     if (fCanUndo) {
  101.         if (fCommandDone) Undo(); 
  102.         else Redo();
  103.         }
  104. }
  105.  
  106. void DCommand::DoIt() 
  107.     fCommandDone= true; 
  108.     SetupMenu("Undo");
  109. }
  110.  
  111. void DCommand::Undo() 
  112.     fCommandDone= false; 
  113.     SetupMenu("Redo");
  114. }
  115.  
  116. void DCommand::Redo() 
  117.     fCommandDone= true; 
  118.     SetupMenu("Undo");
  119. }
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.